package com.zhixun.mobile.modules.jiujiudevice.device.threadpool;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 智能设备 线程池
 * 
 * @author 郝江波
 *
 */
public class SmartThreadPool {
	//最小线程数   
	private static final int MIN = 1000;
	//限制为2000 抛去tomcat的线程数量 保守最大值应该在2000左右
	private static final int MAX = 2000;
	//线程自动回收时间 1秒
	private static final int TIMEOUT = 5;		
	
	//创建线程池  由于智能开关 发一次命令就会断开  所以  用缓冲队列来防止线程过多 造成内存溢出
	private static final ThreadPoolExecutor threadFactory 
	= new ThreadPoolExecutor
			(MIN, MAX, TIMEOUT,TimeUnit.SECONDS,
					new SynchronousQueue<Runnable>());
	/**
	 * 得到线程池线程池
	 * @return
	 */
	public static ThreadPoolExecutor getSmartThreadPool(){
		return threadFactory;	
	}
	
	/**
	 * 运行线程
	 * @param thread
	 */
	public static void execute(Runnable thread){	 
		 threadFactory.execute(thread);	
	}
	
	
	/**
	 * 关闭线程池
	 */
	public static void closeSmartThreadPool(){
		threadFactory.shutdown();
	}
			
			
}
